/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2018-05-07     aozima       the first version
 * 2018-11-16     Ernest Chen  add finsh command and update adc function
 */

#include <rtthread.h>
#include <rtdevice.h>

#include <string.h>
#include <stdlib.h>

#include "app_lcd_drv.h"
#include "app_lcd_util.h"
#include "app_lcd_mp.h"
#include "app_lcd_sm.h"


#ifdef RT_USING_FINSH

static int lcd(int argc, char **argv)
{
    int value = 0;
    int result = RT_EOK;
    static rt_adc_device_t adc_device = RT_NULL;
    char *result_str;

    if (argc > 1) {
        if (!strcmp(argv[1], "msg")) {
            if (argc == 3) {
                //app_lcd_fail_msg_post(argv[2]);
                if (!strcmp(argv[2], "1")) {
                    app_lcd_fail_msg_post(APP_LCD_FAIL_OTP, TRUE);                   
                } else if (!strcmp(argv[2], "2")) {
                    app_lcd_fail_msg_post(APP_LCD_FAIL_METER, TRUE);                 
                } else if (!strcmp(argv[2], "3")){
                    app_lcd_flag_msg_post(APP_LCD_FLAG_ETHE, TRUE, 1);
                    app_lcd_flag_msg_post(APP_LCD_FLAG_WIFI, TRUE, -60);
                    app_lcd_flag_msg_post(APP_LCD_FLAG_4G, TRUE, -60);
                    app_lcd_flag_msg_post(APP_LCD_FLAG_CONN, TRUE, 1);
                } else if (!strcmp(argv[2], "IDLE")) {
                    app_lcd_change_msg_post(APP_LCD_CHR_PLEASE_PLUG_IN);
                } else if (!strcmp(argv[2], "ACCESS")) {
                    app_lcd_change_msg_post(APP_LCD_CHR_SUCCESS_START_CHARGE);
                } else if (!strcmp(argv[2], "CHARGE")) {
                    app_lcd_change_msg_post(APP_LCD_CHR_ON_CHARGING);
                } else if (!strcmp(argv[2], "OK")) {
                    app_lcd_change_msg_post(APP_LCD_CHR_CHARGING_COMPLETE);
                }
                else if (!strcmp(argv[2], "READY")) {
                    app_lcd_change_msg_post(APP_LCD_CHR_ON_READY); 
                }                  
                else if (!strcmp(argv[2], "RETURN")) {
                    app_lcd_change_msg_post(APP_LCD_CHR_CHARGING_RETURN); 
                }                
                 else if (!strcmp(argv[2], "NO")) {
                    app_lcd_fail_msg_post(APP_LCD_FAIL_OTP,FALSE); 
                    app_lcd_fail_msg_post(APP_LCD_FAIL_METER,FALSE);  
                }

                rt_kprintf("msg %s %s \n", argv[2], "success");
            } else {
                rt_kprintf("lcd msg <lcd_name>   - msg lcd by name\n");
            }
        } else if (!strcmp(argv[1], "api")){
            if (argc == 3) {
                rt_kprintf("msg %s %s \n", argv[2], "success");
            } else {
                rt_kprintf("lcd api <lcd_name>   - api lcd by name\n");
            }
        } else {
            rt_kprintf("Unknown command. Please enter 'lcd' for help\n");
        }    
    } else {
        rt_kprintf("Usage: \n");
        rt_kprintf("lcd msg <msg_name>   - msg lcd by name\n");
        rt_kprintf("lcd api <api_name>   - api lcd by name\n");
        result = -RT_ERROR;
    }
    return RT_EOK;
}
MSH_CMD_EXPORT(lcd, lcd function);

#endif /* RT_USING_FINSH */
